home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Cinefil (FR).ifs < prev    next >
Encoding:
Text File  |  2004-10-16  |  13.7 KB  |  345 lines

  1. // GETINFO SCRIPTING
  2. // Cinefil (FR) import avec grande Image
  3.  
  4. (***************************************************
  5.  *  Script d'importation de film pour :            *
  6.  *  CinΘfil.com , http://www.cinefil.com           *
  7.  *                                                 *
  8.  * correction suite α changement du site (v2)      *
  9.  *  (c) 2004 scorpion7552                          *
  10.  * script original par                             *   
  11.  *  (c) 2003 Danone-KiD                            *
  12.  *                                                 *
  13.  *  A utiliser avec Ant Movie Catalog 3.4.2        *
  14.  *  www.antp.be/software/moviecatalog              *
  15.  *                                                 *
  16.  *  This program is free software; you can         *
  17.  *  redistribute it and/or modify it under the     *
  18.  *  terms of the GNU General Public License as     *
  19.  *  published by the Free Software Foundation;     *
  20.  *  either version 2 of the License, or (at your   *
  21.  *  option) any later version.                     *
  22.  ***************************************************)
  23.  
  24. program cinefil;
  25. const
  26.   CinefilBase = 'http://www.cinefil.com';
  27.   CinefilUrl  = CinefilBase + '/cinefil2005/';
  28.   crlf = #13#10;             
  29.   ExternalPictures = False;
  30.   {  True: Les images seront stockΘes en tant que fichiers dans le mΩme dossier que le catalogue
  31.      False: Les images seront stockΘes dans le catalogue (seulement pour les fichiers .amc)  } 
  32.  
  33. var
  34.   MovieName, Line: string;
  35.   BeginPos, EndPos: Integer;
  36.   filmok: Boolean;
  37.  
  38. //------------------------------------------------------------------------------
  39. // RECHERCHE DU FILM (cinΘfil)
  40. //------------------------------------------------------------------------------
  41. procedure AnalyzePageCinefil(Address: string);
  42. var
  43.   Page: TStringList;
  44.   Value,Value2,page_film,titre_film, annee_film,PagePrev,PageNext: string;
  45.  
  46. begin
  47.   filmok := False;
  48.   PageNext := '';
  49.   PagePrev := '';
  50.   PickTreeClear;                                       //vide la liste des films
  51.   PickTreeAdd('Films (CinΘfil)', '');
  52.   Line := GetPage(Address);
  53. // SavePage('d:\Temp\choixCinefil.txt', Line);    // debug
  54.   Value := ExtrStr(Line, '<B> RΘsultat ', '</B>');
  55.   if Value = '' then
  56.   begin
  57.     ShowMessage('CinΘfil: erreur lecture page');          // non trouvΘ = erreur
  58.     exit;
  59.   end;
  60.   if Copy(Value, 1, 1) = '0' then                              // 0 = aucun film
  61.   begin
  62.     ShowMessage('CinΘfil: aucun film trouvΘ pour "' + MovieName + '"');   
  63.     exit; 
  64.   end; 
  65.  
  66. // recherche pages prΘcΘdente et suivante
  67.   Line := ExtrStr(Line, 'RΘsultat', '');
  68.   Value := ExtrStr(Line, '', '</TD>');              // Value = les url des pages
  69.   if Pos('HREF', UpperCase(Value)) = 0 then
  70.     Value := '';                                     // 1 seule page 
  71.   while Value <> '' do
  72.   begin   
  73.   Value2 := ExtrStr(Value, '', '/a>');               // Value2 = url page xxx
  74.   Delete(Value, 1, Pos('</a>', Value)+4);            // Value = les suivantes
  75. // ignorer les "retours rapides" (<< et >>) pour ne pas confondre avec < et > 
  76.   if Pos('><<<', Value2) > 0 then
  77.     continue; 
  78.   if Pos('>>><', Value2) > 0 then
  79.     continue; 
  80.   if Pos('><<', Value2) > 0 then           
  81.   begin                                          // Value2 = url page prΘcΘdente
  82.     PagePrev := GetUrl('', Value2, CinefilBase);
  83.     PickTreeAdd('<<< page prΘcΘdente', PagePrev);
  84.   end;
  85.   if Pos('>><', Value2) > 0 then
  86.     PageNext := GetUrl('', Value2, CinefilBase);   // Value2 = url page suivante 
  87.   end;                                             // end do while value <> ''
  88. // mΘmo des films de cette page
  89.   Value := '<font class=noir>';                           // sΘparateur de films
  90.   repeat
  91. // cherche le lien de la page du film
  92.   BeginPos := Pos(Value, Line);                              // description film
  93.   if BeginPos > 0 then                                          // 1 film trouvΘ
  94.   begin
  95.     Delete(Line, 1, BeginPos-1);
  96. // url de la page
  97.     page_film := GetUrl('HREF=''../fichefilm.cfm?ref=', Line, CinefilUrl);
  98. // annΘe
  99.     annee_film := FormatTitre(ExtrStr(Line, Value, ' '));
  100. // nom du film et rΘalisateur
  101.    BeginPos := Pos('TITLE="', UpperCase(Line));
  102.    Delete(Line, 1, BeginPos);
  103.    titre_film := ExtrStr(Line, '">', '</TD>');
  104.    titre_film := StringReplace(titre_film, '</a>', ',');   // titre, rΘalisateur
  105.    titre_film := FormatTitre(titre_film);
  106. // ajoute le film
  107.     PickTreeAdd(titre_film + ' ' + annee_film , page_film);
  108.   end;
  109.   until BeginPos = 0;
  110.   if PageNext <> '' then
  111.     PickTreeAdd('>>> page suivante', PageNext);     
  112.   if PickTreeExec(Address) then
  113.   begin
  114.     if (Address = PageNext) or (Address = PagePrev) then
  115.       AnalyzePageCinefil(Address)                    // page suivante/prΘcΘdente
  116.     else 
  117.     begin     
  118.       SetField(fieldURL, Address);
  119.       AnalyzePageFilmCinefil(Address);                            // page film
  120.     end;
  121.   end else
  122.     ShowMessage('CinΘfil: aucune page sΘlectionnΘe');
  123. end;
  124.  
  125. //------------------------------------------------------------------------------
  126. // ANALYSE DE LA PAGE DU FILM (CinΘfil)
  127. //------------------------------------------------------------------------------
  128. procedure AnalyzePageFilmCinefil(Address: string);
  129. var
  130.   Value,Value2,Value3,img: string;
  131.  
  132. begin
  133.   filmok := True;
  134.   Line := GetPage(Address);
  135.   Line := ExtrStr(Line, 'RΘfΘrence film cinefil', '');          // vire le dΘbut
  136. // SavePage('d:\Temp\filmCinefil.txt', Line);    // debug
  137. // affiche: test s'il y a un grand format
  138.   img := ExtrStr(Line, 'javascript:ZoomPhoto(''', '''');
  139.   if img = '' then                        // sinon test s'il y a un petit format
  140.     img := ExtrStr(Line, '<IMG class=photo SRC=''', '''');     
  141.   if img <> '' then 
  142.     GetPicture(img, ExternalPictures);
  143. // pays annΘe et durΘe
  144.   Value := ExtrStr(Line, '<font class="smallnoir">', '<BR>');
  145.   Value := StringReplace(Value, '- ', '|');      // sΘpare les champs par |
  146.   HTMLRemoveTags(Value);
  147.   HTMLDecode(Value);
  148.   BeginPos := Pos('|', Value);                       
  149.   Value2 := Copy(Value, 1, BeginPos-1);            // pays (plusieurs possibles)
  150.   Delete(Value, 1, BeginPos);
  151.   if Value2 <> '' then
  152.     SetField(fieldCountry, FormatTitre(Value2));
  153.   BeginPos := Pos('|', Value);
  154.   Value2 := Copy(Value, 1, BeginPos-1);                                 // annΘe
  155.   Delete(Value, 1, BeginPos);
  156.   if Value2 <> '' then
  157.     SetField(fieldYear, FormatTitre(Value2));
  158.   BeginPos := Pos('|', Value);
  159.   Value2 := FormatTitre(Copy(Value, 1, BeginPos-1));                    // durΘe
  160.   BeginPos := Pos('H', UpperCase(Value2));
  161.   Value2 := IntToStr(StrToInt(Copy(Value2, 1, BeginPos-1), 0) * 60 + StrToInt(Copy(Value2, BeginPos+1, 2), 0));
  162.   if Value2 <> '' then
  163.     SetField(fieldLength, FormatTitre(Value2));
  164. // titre original ou traduit
  165.   Value3 := '<font class="noir"><font class="rouge16"><B>';
  166.   BeginPos := Pos(Value3, Line) + Length(Value3);
  167.   Value := ExtrStr(Line, Value3, '</B>');
  168. // titre original Θventuel
  169.   Value3 := '<BR>Titre original :<font class="smallrouge"> <B>';
  170.   Value2 := ExtrStr(Line, Value3, '</B>');
  171.   if Value2 = '' then                                    // 1er titre = original
  172.   begin
  173.     SetField(fieldOriginalTitle, FormatTitre(Value));
  174.     SetField(fieldTranslatedTitle, '');   
  175.   end else
  176.   begin                                                  // traduit + original
  177.     BeginPos := Pos(Value3, Line) + Length(Value3);
  178.     SetField(fieldOriginalTitle, FormatTitre(Value2));
  179.     SetField(fieldTranslatedTitle, FormatTitre(Value)); 
  180.   end; 
  181.   Delete(Line, 1, BeginPos-1);
  182.   EndPos := Pos('</B>', Line);
  183.   Delete(Line, 1, EndPos + 4);
  184. // catΘgorie
  185.   Value := ExtrStr(Line, '<BR>', crlf);
  186.   Value := Trim(Value);
  187.   BeginPos := Pos(' ', Value);                // virer l'article ('un' ou 'une')
  188.   if Pos('UN', UpperCase(Copy(Value, 1, BeginPos))) > 0 then
  189.     Delete(Value, 1, BeginPos);
  190.   if Value <> '' then
  191.     SetField(fieldCategory, FormatTitre(Value));
  192. // rΘalisateur
  193.   Value := ExtrStr(Line, '<B>', '</B>');
  194.   if Value <> '' then
  195.     SetField(fieldDirector, FormatTitre(Value));
  196. // acteurs
  197.   BeginPos := Pos('AVEC', UpperCase(Line));
  198.   Delete(Line, 1, BeginPos);
  199.   Value := ExtrStr(Line, '<B>', crlf);
  200.   if Value <> '' then
  201.     SetField(fieldActors, FormatTitre(Value));   
  202. // description
  203.   Value := ExtrStr(Line, '<font class=smallnoir><BR><font class=noir>', '<BR>');
  204.   if Value <> '' then
  205.     SetField(fieldDescription, FormatText(Value));
  206. { on s'en fout, non?     
  207.   if img = '' then                       
  208.     ShowMessage('CinΘfil: pas d''affiche prΘvue pour "' + MovieName + '"');
  209. }   
  210. end;
  211.  
  212. //------------------------------------------------------------------------------
  213. // formatage d'un texte pour affichage
  214. // suppression des tags html, remplacement des caractΦres bizarres
  215. //------------------------------------------------------------------------------
  216. function FormatText(str1: string) :string;
  217. var
  218.   s: string;
  219.  
  220. begin
  221.   str1 := StringReplace(str1, '<p>', '|');  // remplace temporairement <P> par |
  222.   HTMLRemoveTags(str1);                     // supprime les tags HTML
  223.   HTMLDecode(str1);                         // et les caractΦres spΘciaux
  224. // supprimer les caractΦres de formatage en dΘbut de chaine (code ASCII <= x'20')
  225.   repeat
  226.   s := Copy(str1, 1, 1);                                // 1er caractΦre de str1
  227.   if s <= #32 then
  228.     Delete(str1, 1, 1);                                 // on le vire
  229.   until s > #32;
  230. // remet paragraphe = crlf
  231.   str1 := StringReplace(str1, '|', crlf);
  232. // caractΦres qui s'affichent mal
  233.   str1 := StringReplace(str1, '£', 'oe');       
  234.   str1 := StringReplace(str1, #150, '-');      // le vrai tiret
  235.   str1 := StringReplace(str1, #133, '...');    // les vrais points de suspension
  236.   str1 := StringReplace(str1, #147, '"');      // citation ouvrante = "" ou #171
  237.   str1 := StringReplace(str1, #148, '"');      // citation fermante = "" ou #187
  238.   result := Trim(str1);
  239. end;
  240.  
  241. //------------------------------------------------------------------------------
  242. // formatage d'un titre (sur 1 seule ligne)
  243. //------------------------------------------------------------------------------
  244. function FormatTitre(str1: string) :string;
  245. begin
  246.   HTMLDecode(str1);
  247.   HTMLRemoveTags(str1);
  248.   str1 := StringReplace(str1, crlf, '');                    // sur 1 seule ligne
  249.   result := Trim(str1);
  250. end;
  251.  
  252. //------------------------------------------------------------------------------
  253. // extraction d'une url contenue dans une chaine de caractΦres sans Θdition
  254. // adr := GetUrl(texte_HREF_cherchΘ,chaine,url_de_base)
  255. //------------------------------------------------------------------------------
  256. function GetUrl(strfrom,str1,urlb: string) :string;
  257. var
  258.  i: Integer;
  259.  delim: String;
  260.  
  261. begin
  262.   if strfrom <> '' then                        // si from = '' on part du dΘbut
  263.   begin
  264.     i := Pos(strfrom, str1);                   // position href cherchΘ
  265.     if i = 0 then                              // rien trouvΘ
  266.     begin
  267.       result := '';
  268.       exit;
  269.     end; 
  270.     Delete(str1,1, i -1);
  271.   end; 
  272.   i := Pos('HREF=', UpperCase(str1));        // debut url: href= 
  273.   delim := Copy(str1, i+5, 1);               // fin = " ou '
  274.   Delete(str1,1, i +5);
  275.   i := Pos(delim, str1);   
  276.   if i > 0 then
  277.     Delete(str1,i, Length(str1));
  278. // il y a parfois des trucs en plus aprΦs l'url: donc α supprimer     
  279.   i := Pos('&mc=', str1);
  280.   if i > 0 then                           
  281.     Delete(str1, i, Length(str1));
  282.   str1 := StringReplace(str1, '../', '');    // cf adresse relative
  283.   str1 := StringReplace(str1, './', '');     
  284.   str1 := urlb + str1;                       // ajoute url de base   
  285.   result := Trim(str1);
  286. end;
  287.  
  288. //------------------------------------------------------------------------------
  289. // extraction de la chaine dΘlimitΘe par from et to dans str1
  290. //------------------------------------------------------------------------------
  291. function ExtrStr(str1,strfrom,strto: string) :string;
  292. var
  293.  i: Integer;
  294.  
  295. begin
  296.   if strfrom <> '' then                         // si from = '' on part du dΘbut
  297.   begin
  298.     i := Pos(strfrom, str1);
  299.     if i = 0 then                                             // from non trouvΘ
  300.     begin
  301.       result := '';
  302.       exit;
  303.     end; 
  304.     Delete(str1, 1, i + Length(strfrom) -1);
  305.   end; 
  306.   i := Pos(strto, str1);                                     // fin de la chaine
  307.   Delete(str1, i, Length(str1));
  308.   result := Trim(str1);
  309. end;
  310.  
  311. //------------------------------------------------------------------------------
  312. // Θcriture d'une chaine sur disque (pour debug...)
  313. // SavePage(chemin_du_fichier,chaine)
  314. // chemin_du_fichier = chemin complet ex: 'c:\temp\monfichier.txt'
  315. //------------------------------------------------------------------------------
  316. procedure SavePage(fic, str1: string);
  317. var
  318.   Page2: TStringList;
  319.  
  320. begin
  321.   page2 := TStringList.Create;
  322.   page2.Text := str1;
  323.   page2.SaveToFile(fic);
  324. end;
  325.  
  326. //------------------------------------------------------------------------------
  327. //  c'est ici que τa commence 
  328. //------------------------------------------------------------------------------                                               
  329. begin
  330.   if CheckVersion(3,4,2) then
  331.   begin
  332. // cinΘfil prΘfΦre les titres en franτais (peut-Ωtre plus vrai,, mais bon...)
  333.     MovieName := GetField(fieldTranslatedTitle);
  334.     if MovieName = '' then
  335.        MovieName := GetField(fieldOriginalTitle);
  336.     if Input('cinΘfil.com Import avec image', 'Entrez le titre du film :', MovieName) then
  337.     begin
  338.       AnalyzePageCinefil(CinefilUrl + 'CFM_Recherches/films.cfm?lachaine2=' + UrlEncode(MovieName));       
  339.       if filmok then
  340.         DisplayResults;
  341.     end;   
  342.   end else
  343.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.2)');
  344. end.
  345.